import { createRouter, createWebHistory } from 'vue-router'
import Home from '@/views/home/home.vue'
const routes = [
  {
    path: '/',
    name: 'home',
    meta: {
      name: "home",
      title: 'VUE3-音乐播放',
      keepalive: true,
      showTabbar:true,
    },
    component: Home,

  },
  {
    path: '/home',
    redirect: '/'
  },
  {
    path: "/user",
    name: "user",
    meta: {
      name: "user",
      title: '个人中心',
      keepalive: true,
      showTabbar:true,

    },
    component: () => import(/* webpackChunkName: "user" */ "../views/user/user.vue"),
  },
  {
    path: "/music",
    name: "music",
    component: () => import(/* webpackChunkName: "music" */ "../views/music/music.vue"),
    meta: {
      name: "music",
      title: '歌单',
      keepalive: true,
      showTabbar:true,
    },
  },
  {
    path: "/music/musicListDetail",
    name: "musicListDetail",
    component: () => import(/* webpackChunkName: "musicListDetail" */ "../views/music/musicListDetail.vue"),
    meta: {
      keepalive: false,
    },
  },
  {
    path: "/login",
    name: "login",
    meta: {
      title: '用户登录'
    },
    component: () => import(/* webpackChunkName: "login" */ "../views/login/login.vue"),

  },
  {
    path: "/comment",
    name: "comment",
    component: () => import(/* webpackChunkName: "comment" */ "../views/player/comment.vue"),
  },
  {
    path: "/search",
    name: "search",
    component: () => import(/* webpackChunkName: "search" */ "../views/search/search.vue"),
    meta:{
      keepalive:true,
      showTabbar:true,

    }
  },
  
];



const router = createRouter({
  history: createWebHistory(),
  routes,
});

router.beforeEach((to, from, next) => {
  // 根据路由元信息设置文档标题
  if(to.meta.title){
    window.document.title = to.meta.title;
  }else{
    window.document.title = 'VUE3-音乐播放';
  }
  
  
  next()
})

export default router;